<?php
//---------------------------------------------------------------------------------------------------------------------------
    include_once($config['app_dir'] . '/includes/object.class.php');
    //-------------------------------------------------------------------------------------------------------------------
    class objSimpleList extends objObject  implements iDebug, Iterator{
            protected $items;
            protected $valid;

        function __construct() {
            $this->items = array();
        } //constructor objSimpleList

        public function ClassName() {
            return  __CLASS__;
        }//ClassName

        //--------------------------------------------------------------------------------------------
        function add(objObject $item) {
            if ( $item->isEmpty() ) return false;
            $i = count($this->items);
            $this->items[$i] = $item;
            return true;
        }//add

        function clear() {
            unset($this->items);
            $this->items = array();
        }//clear

        function supress() {
            $items = array(); $c=0;
            foreach($this-> items as $item)
                if ( !$item->isEmpty() ) $items[$c++] = $item;
            $this->items = $items;
        }//supress

        function length() {
            return count($this->items);
        }//length

        function merge($items) {
            foreach($items as $item)
                $this->add($item);
        } //merge

        function isEmpty() {
            return 0==$this->length();
        }//isEmpty

        //--------------------------------------------------------------------------------------------
        function dump() {
            echo '<br> Simplelist dump: ';
            echo '<br> items '; var_dump($this->items);
        }//dump

        //--------------------------------------------------------------------------------------------
        // Iterator
        //--------------------------------------------------------------------------------------------

        function rewind() {
            $this->valid = (FALSE !== reset($this->items));
        } //rewind

        function current() {
            return current($this->items);
        } //current

        function key() {
            return key($this->items);
        } //key

        function next() {
            $this->valid = (FALSE !== next($this->items));
        } //next

        function valid() {
            return $this->valid;
        } //valid
    } //class objSimpleList

    //----------------------------------------------------------------------------------------------------------------------
    class objIndexList extends objSimpleList  implements iDebug, Iterator, ArrayAccess{

        public function ClassName() {
            return  __CLASS__;
        }//ClassName

        //--------------------------------------------------------------------------------------------
        // ArrayAccess
        //--------------------------------------------------------------------------------------------

        function offsetSet($key, $value) {
            if (array_key_exists($key, $this->items))
                $this->items[$key] = $value;
        } //offsetSet

        function offsetGet($key) {
            if (array_key_exists($key, $this->items))
                return $this->items[$key];
        } //offsetGet

        function offsetUnset($key) {
            if (array_key_exists($key, $this->items))
                unset($this->items[$key]);
        } //offsetUnset

        function offsetExists($offset) {
            return array_key_exists($key, $this->items);
        } //offsetExists

    } //class objIndexList
//---------------------------------------------------------------------------------------------------------------------------

?>
